<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 引入样式 -->
<style>
    .container {
        width: 100%;
    }
</style>

<div id="member-add-app" class="addBrand-container">
    <div class="container">
        <form class="el-form demo-ruleForm">
            <div class="el-form-item is-required">
                <label for="username" class="el-form-item__label" style="width: 180px;">内容:</label>
                <div class="el-form-item__content" style="margin-left: 180px;">
                    <div class="el-input">
                        <input type="text" autocomplete="off" placeholder="请输入内容" maxlength="20" class="el-input__inner" id="username">
                    </div>
                </div>
            </div>
            <div class="el-form-item is-required">
                <label for="data" class="el-form-item__label" style="width: 180px;">公告时间:</label>
                <div class="el-form-item__content" style="margin-left: 180px;">
                    <div class="el-input">
                        <input type="date" autocomplete="off" placeholder="请输入公告时间" maxlength="20" class="el-input__inner" id="data">
                    </div>
                </div>
            </div>
            <div class="el-form-item is-required">
                <label for="dataId" class="el-form-item__label" style="width: 180px;">创建时间:</label>
                <div class="el-form-item__content" style="margin-left: 180px;">
                    <div class="el-input">
                        <input type="date" autocomplete="off" placeholder="请输入创建时间" maxlength="20" class="el-input__inner" id="dataId">
                    </div>
                </div>
            </div>
            <div class="subBox address">
                <div class="el-form-item">
                    <div class="el-form-item__content" style="margin-left: 180px;">
                        <button type="button" class="el-button el-button--default">
                            <span>取消</span>
                        </button>
                        <button type="button" class="el-button el-button--primary">
                            <span>保存</span>
                        </button>
                        <button type="button" class="el-button continue el-button--primary">
                            <span>保存并继续添加</span>
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="api/member/member.js"></script>
<script>
    $(function(){
        loadRolesData();//初始加载角色数据
        $(".el-button--default").on("click",backToItemList);
        $(".el-button--primary").on("click",saveAddOrUpdate);
    })

    //添加或修改用户
    function saveAddOrUpdate() {
        var addNotice="notice/addNotice";
        var updateNotice="notice/updateNotice";

        var username=$("#username").val();
        var date=$("#data").val();
        var dateId=$("#dataId").val();
        if(!username){
            commonShowTips("请填写内容");
            return;
        }
        var params={
            noticeContent:username,
            noticeTimeStr:date,
            createdTimeStr:dateId
        };
        var url = !$("#cIframe").data("notId") ? addNotice : updateNotice;

        if($("#cIframe").data("notId")){
            params.id = $("#cIframe").data("notId");
        }
        $.get(url,params,function (result){
            commonShowTips(result.message);
            backToItemList();
        })
    }
    //初始加载角色数据
    function loadRolesData(){
        var url = "notice/findAll";
        $.get(url,{},function (result){
            result = result.data;
            for(var i in result){
                var id = result[i].id;
                var str ="<li class='role-li' style='list-style-type: none ;float: left' >"
                    + "<input type='checkbox' value='role"+ id + "' id='role"+ id + "'>"
                    + "<label for='role"+ id +"'>" + result[i].notName + "</label></li>"
                $(".roles-ul").append(str)
            }
            if ($("#cIframe").data("notId")){
                //如果是修改就填充数据
                initUpdataNoticeData();
            }
        })
    }
    //修改
    function initUpdataNoticeData(){
        var notice=$("#cIframe").data("notice");
        $("#username").val(notice.noticeContent);
        $("#data").val(notice.noticeTime);
        $("#dataId").val(notice.createdTime);
        var param ={notId:$("#cIframe").data("notice").id}
        $("#dataId").attr("readonly", "readonly");
    }
    /**
     * 返回商品集合主界面   
     */
    function backToItemList() {
        $("#cIframe").data("notId","");
        $("#cIframe").load("notice/list");
    }
</script>